package com.mxfcode.front.bbs_comment.controller;

import com.mxfcode.bbs_common.date.DateUtils;
import com.mxfcode.bbs_common.util.community.CommunityConstant;
import com.mxfcode.bbs_common.util.page.Page;
import com.mxfcode.common.HostHolder;
import com.mxfcode.entity.BBSArticle;
import com.mxfcode.entity.BBSComment;
import com.mxfcode.entity.TSUser;
import com.mxfcode.front.bbs_article.service.ArticleService;
import com.mxfcode.front.bbs_comment.service.CommentService;
import com.mxfcode.front.bbs_login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author moxiufeng
 * @date 2021/2/27 23:03
 */
@Controller
@RequestMapping("/comment")
public class CommentController implements CommunityConstant {
    @Autowired
    private CommentService commentService;

    @Autowired
    private HostHolder hostHolder;

    @PostMapping(path = "/add/{articleId}")
    public String addComment(@PathVariable("articleId") String articleId, BBSComment comment) {
        comment.setUserId(hostHolder.getUser().getId());
        comment.setStatus(0);
        comment.setCreateDate(DateUtils.getCurrentDateToDate());
        commentService.addComment(comment);
        return "redirect:/article/detail/" + articleId;
    }

    @PostMapping(path = "/addAnswerQuestions/{answerQuestionsId}")
    public String addAnswerQuestionsComment(@PathVariable("answerQuestionsId") String answerQuestionsId, BBSComment comment) {
        comment.setUserId(hostHolder.getUser().getId());
        comment.setStatus(0);
        comment.setCreateDate(DateUtils.getCurrentDateToDate());
        commentService.addAnswerQuestionsComment(comment);
        return "redirect:/answerQuestions/detail/" + answerQuestionsId;
    }
}
